var accessControl_list = {
  "xiaoqu": [{
    "accesscontrol_id": "4",
    "deviceName": "小区东门门禁",
    "bind_gate": "小区东门"
  }],
  "danyuan": {
    "1号楼": {
      "1单元": {
        "accesscontrol_id": "3",
        "deviceName": "一号楼二单元门禁"
      }
    }
  }
}


function toTreeData(obj, ret = []) {
  let keys = Object.keys(obj)
  if (keys.length > 0) {
    for (let i = 0; i < keys.length; i++) {
      current = obj[keys[i]]
      console.log('current,', current)
      if (Array.isArray(current)) {
        ret.push(current)
      } else if (typeof current === 'object') {
        let data = {
          title: keys[i],
          expand: true,
          children: []
        }
        ret.push(data)
        toTreeData(current, data.children)
      }
    }
  }
}
// function repateToTree(obj,ret=[]){
//   let keys = Object.keys(obj)
//   if (keys.length > 0) {
//     for (let i = 0; i < keys.length; i++) {
//       current = obj[keys[i]]
//       console.log('repateToTree current,', current)
//       if (Array.isArray(current)) {
//         ret.push(current)
//       } else {
//         let data = {
//           title: keys[i],
//           expand: true,
//           children: []
//         }
//         ret.push(data)
//       }
//     }
//   }
// }
let data = []
toTreeData(accessControl_list, data)
console.log('data', data)
